package week_06;

public class Bag_0_1_all {
    public int maxValueBag(int[][] nums, int m) {
        int n = nums.length;
        int[] dp = new int[m+1];
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            int v = nums[i][0];
            int w = nums[i][1];
            for (int j = v; j <= m; j++) {
                dp[j] = Math.max(dp[j], dp[j - v] + w);
            }
        }
        int ans = 0;
        for (int j = 1; j <= m; j++) {
            ans = Math.max(ans, dp[j]);
        }
        return ans;
    }

    public static void main(String[] args) {
        int[][] arr = new int[][]{{2, 5}, {1, 2}, {4, 6}};
        Bag_0_1_all test = new Bag_0_1_all();
        test.maxValueBag(arr, 4);
    }
}
